<?php include("includes/session.php"); ?>
<?php include("includes/connect_db.php"); ?>
<?php include("includes/header.php"); ?>
<?php include("notif.php"); ?>

<style>
	.ket, .del {
		cursor: pointer;
	}
	.btn{
		width: 100px;
	}
</style>

<script type="text/javascript">
	$(document).ready(function() {
		$('#example').dataTable( {
			"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
			"sPaginationType": "bootstrap",
			"aoColumns": [
				{ "sClass": "center", "bSearchable": false, "bSortable": false },
				{ "sClass": "center", "bSearchable": true, "bSortable": true },
				{ "sClass": "center", "bSearchable": true, "bSortable": false }
			],
			"oLanguage": {
				"sLengthMenu": "_MENU_ records per page"
			}
		} )	
	} );
</script>

<div class="span9">  
    <h3>SMS</h3>                      
    <ul class="breadcrumb well">
        <li class="active">Master Agregat</li>                
    </ul>    
    
    <div>
		<button class="btn btn-info but-add" type="button">
			<i class="icon-plus icon-white"></i>
			Tambah
		</button>
		<hr width="100%">
	</div>
	<div>
	    <table class="table table-striped table-bordered" id="example">
	        <thead>
	        	<tr>
	            	<th>
	            		No
	            	</th>
	            	<th>
	            		Nama Agregat
	            	</th>
	            	<th>
	            		Keterangan
	            	</th>
	        	</tr>
	        </thead>
	        <tbody>  
	        	<?php
	        		$i = 1;
	        		$sql_ambil_data = "SELECT * FROM tb_master_agregat";
	        		$query_ambil_data = mysql_query($sql_ambil_data);
	        		while ($ambil_data = mysql_fetch_array($query_ambil_data)) {
	        	?>
	        	<tr>
	        		<td>
	        			<?php echo $i;?>
	        			<input type="hidden" class="id" value="<?php echo $ambil_data['id_agregat'] ?>">
	        		</td>
	        		<td>
	        			<?php echo $ambil_data['agregat']; ?>
	        		</td>
	        		<td>
	        			<i class="icon-edit ket" data-placement="left" title="Edit Agregat"></i>
	        			<i class="icon-trash del" data-placement="right" title="Hapus Agregat"></i>
	        		</td>
	        	</tr>     
	        	<?php
	        			$i++;
	        		}
	        	?>
	    	</tbody>
		</table>
	</div>
</div><!--/span-->

<?php include("includes/footer.php"); ?>

<script type="text/javascript">
	$(document).ready(function() {
		$('.icon-trash').click(function(){
			var form_agregat = {
                id : $(this).parent('td').parent('tr').find('.id').val()
            };
            $.ajax({ 
                type: "POST",
                url: "act_agregat.php",
                data: form_agregat, 
                cache: false, 
                success: function(msg){ 
                    location.reload();
                } 
            });
		});

		$('.but-add').click(function(){
			window.location = "agregat-tambah.php";
		});

		$('.icon-edit').click(function(){
			id = $(this).parent('td').parent('tr').find('.id').val();
			window.location = "agregat-edit.php?id="+id;
		});

		$('.ket').tooltip();
		$('.del').tooltip();
	});
</script>